package com.xinruke.hostels.systemmanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.system.manage.interfaces.dto.*;
import com.xinruke.hostels.systemmanage.service.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author yutaipu
 */
@RestController
@RequestMapping("/room/")
@Api(tags = "房间")
@Slf4j
public class RoomController extends BaseController {

    @Autowired
    private RoomService roomService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResultVO add(@Valid @RequestBody RoomAddDTO addQueryDTO) {
        return roomService.add(addQueryDTO);
    }

    @PostMapping("/modify")
    @ApiOperation("修改")
    public ResultVO modify(@Valid @RequestBody RoomModifyDTO modifyQueryDTO) {
        return roomService.modify(modifyQueryDTO);
    }

    @PostMapping("/del")
    @ApiOperation("删除")
    public ResultVO delete(@Valid @RequestBody RoomDelQueryDTO delQueryDTO) {
        return roomService.delete(delQueryDTO);
    }

    /**
     * 通过酒店id查询旗下所有房间
     */
    @PostMapping("/hotel")
    @ApiOperation(value = "查询酒店下的所有房间")
    public ResultVO<RowsDataVO<RoomQueryResultDTO>> getRoomList(@Valid @RequestBody RoomQueryDTO roomQueryDTO) {
        ResultVO<RowsDataVO<RoomQueryResultDTO>> resultVO = ResultVO.fail();
        RowsDataVO<RoomQueryResultDTO> dataVO = roomService.getRoomList(roomQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataVO);
        return resultVO;
    }

    /**
     * 通过id查询详情
     *
     * @return 房间详情
     */
    @PostMapping("/detail")
    @ApiOperation(value = "查询房间详情")
    public ResultVO<RoomDetailQueryResultDTO> getDetail(@Valid @RequestBody RoomDetailQueryDTO detailQueryDTO) {

        RoomDetailQueryResultDTO detail = roomService.getDetail(detailQueryDTO);
        ResultVO<RoomDetailQueryResultDTO> resultVO = ResultVO.success();
        resultVO.setMessage("操作成功");
        resultVO.setData(detail);
        return resultVO;
    }

    /**
     * 查询酒店下拥有的房间数量
     *
     * @param countQueryDTO 酒店id
     * @return 酒店拥有的房间数量
     */
    @PostMapping("/count")
    @ApiOperation(value = "查询房间数量")
    public ResultVO<Integer> count(@Valid @RequestBody RoomCountQueryDTO countQueryDTO) {

        Integer count = roomService.count(countQueryDTO);
        ResultVO<Integer> resultVO = ResultVO.success();
        resultVO.setMessage("操作成功");
        resultVO.setData(count);
        return resultVO;
    }

    @PostMapping("/addBatch")
    @ApiOperation(value = "批量新增房间")
    public ResultVO<Integer> addBatch(@Valid @RequestBody RoomAddBatchDTO params) {
        return roomService.addBatch(params);
    }

    /**
     * 获取房间未使用集合
     *
     * @return
     */
    @PostMapping("/getRoomUnusedList")
    @ApiOperation(value = "获取房间未使用集合")
    public ResultVO<RowsDataVO<RoomUnusedQueryResultDTO>> getRoomUnusedList(@Valid @RequestBody RoomUnusedQueryDTO roomUnusedQueryDTO) {
        ResultVO<RowsDataVO<RoomUnusedQueryResultDTO>> resultVO = ResultVO.fail();

        RowsDataVO<RoomUnusedQueryResultDTO> rowsDataVO = roomService.getRoomUnusedList(roomUnusedQueryDTO);

        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("SUCCESS");
        resultVO.setData(rowsDataVO);
        return resultVO;
    }

}
